
var WindCrumbs = new Object();

WindCrumbModel = function() {
}

WindCrumbModel.prototype.setTitle = function(title) {
	this.title = title;
}

WindCrumbModel.prototype.getTitle = function() {
	return this.title;
}

WindCrumbModel.prototype.setView = function(view) {
	this.view = view;
}

WindCrumbModel.prototype.getView = function() {
	return this.view;
}

WindCrumbs.createModel = function() {
	var crumbsModel = new Object();
	
	crumbsModel.getNumberOfCrumbs = function() {
		return 3;
	}
	
	crumbsModel.getCrumbAtIndex = function(index) {
		if(index==0) {
			var crumbModel = new WindCrumbModel();
			crumbModel.setTitle("Hello");
			var crumbView = WindCrumbs.createCrumbView(crumbModel);
			crumbModel.setView(crumbView);
			return crumbModel;
		} else if(index==1) {
			var crumbModel = new WindCrumbModel();
			crumbModel.setTitle("World");
			var crumbView = WindCrumbs.createCrumbView(crumbModel);
			crumbModel.setView(crumbView);
			return crumbModel;
		} else if(index==2) {
			var crumbModel = new WindCrumbModel();
			crumbModel.setTitle("From Mars");
			var crumbView = WindCrumbs.createCrumbView(crumbModel);
			crumbModel.setView(crumbView);
			return crumbModel;
		} 
	}

	return crumbsModel;
}

WindCrumbs.createView = function(crumbsModel) {

	if(crumbsModel==null) {
		crumbsModel = WindCrumbs.createModel();
	}

	var crumbsView = new WindView();
	crumbsView.setCssClass("WindCrumbs");
	
	for(var i=0; i<crumbsModel.getNumberOfCrumbs(); i++) {
		var crumbModel = crumbsModel.getCrumbAtIndex(i);
		var crumbView = crumbModel.getView();
		crumbsView.addView(crumbView);
	}
	
	crumbsView.render = function() {
		var ul = document.createElement("ul");
		
		crumbsView.setHtmlElement(ul);
		
		this.applyViewAttributesToHtmlElement(ul);

		this.renderChildren(ul);
	
		return ul;
	}
	
	return crumbsView;
}

WindCrumbs.createCrumbView = function(crumbModel) {
	var crumbView = new WindView();
	crumbView.setCssClass("WindCrumbs");
	
	crumbView.render = function() {
		var li = document.createElement("li");
		crumbView.setHtmlElement(li);
		
		this.applyViewAttributesToHtmlElement(li);

		var a = document.createElement("a");
		a.innerHTML = crumbModel.getTitle();
		a.href = "#";
		li.appendChild(a);

		this.renderChildren(li);
	
		return li;
	}
	
	return crumbView;
}

